/*
 * Copyright @ 2024 weili23
 * com.example.mythread.a06threadWaitAndNotify 10:52
 * All right reserved.
 */

package com.example.mythread.a06threadWaitAndNotify;

import ch.qos.logback.core.net.SyslogOutputStream;

/**
 * @desc: 生产者
 * @author: weili23
 * @createTime: 2024/10/21 10:52
 * @version: v1.0
 */
public class Cook extends Thread{
    @Override
    public void run() {

        while (true){
            synchronized (Desk.lock){
                if (Desk.foodNum == 0){
                    //消费者吃不下了，已经吃完10碗面条了
                    System.out.println("厨师类：吃货吃不下了，已经吃完10碗面条了");
                    break;
                }else{
                    //判断桌子上有没有面条
                    if(Desk.foodFlag ==1){
                        //有面条就等待消费者吃、
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else{
                        //没有面条就生产面条，
                        System.out.println("厨师生产面条了");
                        Desk.foodFlag = 1;
                        //叫醒消费者来消费面条
                        Desk.lock.notifyAll();
                    }
                }
            }
        }
    }
}
